﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Dashboard.Expense.Business
{
    public enum ExpenseTypes
    {
        Normal,
        Breakfast,
        Lunch,
        Supper,
        Hotel
    }

    public class Exp_ExpenseType : BusinessBase
    {
        public DataTable QueryApplicationTypes()
        {
            string sql = "select * from exp_applicationtypes order by id";
            return DbConnection.DataSet(sql).Tables[0];
        }

        public void DeleteApplicationTypes(int typeID)
        {
            string sql = "delete from exp_applicationtypes where id=" + typeID;
            DbConnection.ExecuteSql(sql);

            sql = "delete from exp_feetypes where typeid=" + typeID;
            DbConnection.ExecuteSql(sql);
        }

        public void AddApplicationType(string code, string description)
        {
            string currentUser = CommonBusiness.GetCurrentLoginUser();
            string sql = @"insert into Exp_ApplicationTypes(code,description,insertby,insertdate,updatedby,updateddate) 
                            VALUES('{0}','{1}','{2}',getdate(),'{3}',getdate())";
            sql = string.Format(sql, base.FormatStringForSqlVariable(code),
                                base.FormatStringForSqlVariable(description),
                                currentUser, currentUser);

            DbConnection.ExecuteSql(sql);
        }

        public DataTable QueryExpenseTypes(int typeID)
        {
            string sql = "select * from exp_feetypes where typeid=" + typeID + " order by id";
            return DbConnection.DataSet(sql).Tables[0];
        }

        public void DeleteExpense(int id)
        {
            string sql = "delete from exp_feetypes where id=" + id;
            DbConnection.ExecuteSql(sql);
        }

        public void AddExpense(int typeID, string code, string description, string expenseType)
        {
            string currentUser = CommonBusiness.GetCurrentLoginUser();
            string sql = @"insert into Exp_FeeTypes(typeid,code,description,feetype,insertby,insertdate,updatedby,updateddate) 
                            VALUES({4},'{0}','{1}','{5}','{2}',getdate(),'{3}',getdate())";
            sql = string.Format(sql, base.FormatStringForSqlVariable(code),
                                base.FormatStringForSqlVariable(description),
                                currentUser, currentUser, typeID, expenseType);

            DbConnection.ExecuteSql(sql);
        }
    }
}
